package com.hzdl.goods.controller;

import com.hzdl.goods.entity.Goods;
import com.hzdl.goods.service.GoodsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    private static final Logger log = LoggerFactory.getLogger(GoodsController.class);

    @Autowired
    private GoodsService goodsService;

    @Value("${server.port}")
    private String port;

    //查询所有商品
    @GetMapping("/all")
    public List<Goods> findAll() {
        return goodsService.findAll();
    }

    //根据ID查询商品
    @GetMapping("/{id}")
    public Optional<Goods> findById(@PathVariable("id") Long id) {
        log.info("调用商品微服务，端口号为："+port);
        return goodsService.findById(id);
    }
}
